package com.hao.study.config;

import com.hao.study.service.ErrorLogCleanupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author: author
 * @description:       定时清理错误日志配置类 默认30天
 * @date: 2024/6/14 11:41
 * @version: 1.0
 */
@Configuration
@EnableScheduling
public class AppConfig {


    private final int daysBefore = 30;

    @Autowired
    private ErrorLogCleanupService errorLogCleanupService;
    @Bean
    public Runnable errorLogCleanupTask() {
        return () -> errorLogCleanupService.cleanupErrorLogs(daysBefore);
    }
    @Scheduled(cron = "0 0 0 * * ?")
    public void scheduleErrorLogCleanup() {
        errorLogCleanupTask().run();
    }
}
